# -*- coding: utf-8 -*-
import io
import sys
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') #改变标准输出的默认编码

import csv
dict_mashup_to_api = {

}
with open("data_api.csv", encoding='utf-8', mode="r", errors='ignore') as f:
    reader = csv.reader(f)
    for row in reader:
        if row[0] in dict_mashup_to_api:
            continue
        else:
            dict_mashup_to_api[row[0]] = row[1]


with open('mashup_api_style.csv', "w", newline='', encoding='utf-8', errors='ignore') as f:
    writer = csv.writer(f)
    with open("m-a_edges.csv", encoding='utf-8', mode="r", errors='ignore') as f:
        reader = csv.reader(f)
        for row in reader:
            if row[1] in dict_mashup_to_api.keys():
                data = [row[0], row[1], dict_mashup_to_api[row[1]]]
                writer.writerow(data)
